package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
	@Select("select * from address_book where user_id = #{userId}")
	List<AddressBook> list(AddressBook addressBook);

	void save(AddressBook addressBook);

	@Select("select * from address_book where id = #{id}")
	AddressBook getById(Long id);

	void update(AddressBook addressBook);

	@Update("update address_book set is_default = 1 where user_id = #{userId} and id = #{id}")
	void updateDefault(AddressBook addressBook);

	@Select("select * from address_book where user_id = #{userId} and is_default = 1")
	AddressBook getDefault(Long userId);

	@Update("update address_book set is_default = 0 where user_id = #{userId}")
	void updateIsDefaultByUserId(AddressBook addressBook);

	//@Select("select * from address_book where user_id = #{userId} and is_default = 1")
	//void queryDefault(Long userId);
}
